<!DOCTYPE html>
<html lang='zh-CN'>

<head>
  <meta name="generator" content="Hexo 6.3.0">
  <meta name="hexo-theme" content="https://github.com/xaoxuu/hexo-theme-stellar/tree/1.19.0">
  <meta charset="utf-8">
  

  <meta http-equiv='x-dns-prefetch-control' content='on' />
  <link rel='dns-prefetch' href='https://gcore.jsdelivr.net'>
  <link rel="preconnect" href="https://gcore.jsdelivr.net" crossorigin>
  <link rel='dns-prefetch' href='//unpkg.com'>

  <meta name="renderer" content="webkit">
  <meta name="force-rendering" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  <meta name="HandheldFriendly" content="True" >
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="theme-color" content="#f8f8f8">
  
  <title>Nacos使用笔记 - 愔颂</title>

  
    <meta name="description" content="微服务部署下使用Nacos集成服务注册和发现，配置管理。">
<meta property="og:type" content="article">
<meta property="og:title" content="Nacos使用笔记">
<meta property="og:url" content="https://farhills.gitee.io/2023/10/05/Nacos%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/index.html">
<meta property="og:site_name" content="愔颂">
<meta property="og:description" content="微服务部署下使用Nacos集成服务注册和发现，配置管理。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.nlark.com/yuque/0/2023/png/36098302/1695641030655-435693bd-e552-4487-a943-ec1786855ca9.png">
<meta property="og:image" content="https://cdn.nlark.com/yuque/0/2023/png/36098302/1695783332627-d8a70864-b408-4640-9b3f-9cc3ffb5df37.png">
<meta property="og:image" content="https://cdn.nlark.com/yuque/0/2023/png/36098302/1695783517983-78bab6b2-f7e6-46cc-809d-c6bd9fd3e104.png">
<meta property="article:published_time" content="2023-10-05T03:13:35.015Z">
<meta property="article:modified_time" content="2023-10-04T11:46:21.986Z">
<meta property="article:author" content="远岫">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.nlark.com/yuque/0/2023/png/36098302/1695641030655-435693bd-e552-4487-a943-ec1786855ca9.png">
  
  
  
  

  <!-- feed -->
  

  
    
<link rel="stylesheet" href="/css/main.css">

  

  
    <link rel="shortcut icon" href="https://z1.ax1x.com/2023/10/05/pPXijyT.png">
  

  

  


  
</head>

<body>
  




  <div class='l_body' id='start'>
    <aside class='l_left' layout='post'>
    

  

<header class="header"><div class="logo-wrap"><a class="avatar" href="/about/"><div class="bg" style="opacity:0;background-image:url(https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.4/avatar/round/rainbow64@3x.webp);"></div><img no-lazy class="avatar" src="https://s1.ax1x.com/2022/11/12/ziJjfK.jpg" onerror="javascript:this.classList.add('error');this.src='https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.4/image/2659360.svg';"></a><a class="title" href="/"><div class="main" ff="title">愔颂</div></a></div>

<nav class="menu dis-select"><a class="nav-item active" href="/">文章</a><a class="nav-item" href="/friends/">收藏</a><a class="nav-item" href="/about/">关于</a></nav>
</header>


<div class="widgets">
<widget class="widget-wrapper search"><div class="widget-body"><div class="search-wrapper" id="search"><form class="search-form"><input type="text" class="search-input" id="search-input" data-filter="/blog/" placeholder="文章搜索"><svg t="1670596976048" class="icon search-icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2676" width="200" height="200"><path d="M938.2 832.6L723.8 618.1c-2.5-2.5-5.3-4.4-7.9-6.4 36.2-55.6 57.3-121.8 57.3-193.1C773.3 222.8 614.6 64 418.7 64S64 222.8 64 418.6c0 195.9 158.8 354.6 354.6 354.6 71.3 0 137.5-21.2 193.2-57.4 2 2.7 3.9 5.4 6.3 7.8L832.5 938c14.6 14.6 33.7 21.9 52.8 21.9 19.1 0 38.2-7.3 52.8-21.8 29.2-29.1 29.2-76.4 0.1-105.5M418.7 661.3C284.9 661.3 176 552.4 176 418.6 176 284.9 284.9 176 418.7 176c133.8 0 242.6 108.9 242.6 242.7 0 133.7-108.9 242.6-242.6 242.6" p-id="2677"></path></svg></form><div id="search-result"></div><div class="search-no-result">没有找到内容！</div></div></div></widget>


<widget class="widget-wrapper toc single" id="data-toc"><div class="widget-header cap dis-select"><span class="name">Nacos使用笔记</span></div><div class="widget-body fs14"><div class="doc-tree active"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#1%E3%80%81Spring-Cloud%E6%95%B4%E5%90%88Nacos%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83"><span class="toc-text">1、Spring Cloud整合Nacos注册中心</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-1%E3%80%81%E5%BC%95%E5%85%A5Nacos%E6%9C%8D%E5%8A%A1%E5%8F%91%E7%8E%B0%E7%BB%84%E4%BB%B6"><span class="toc-text">1.1、引入Nacos服务发现组件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-2%E3%80%81%E4%B8%8B%E8%BD%BDNacos-Server%E5%B9%B6%E5%90%AF%E5%8A%A8"><span class="toc-text">1.2、下载Nacos Server并启动</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-3%E3%80%81%E9%85%8D%E7%BD%AENacos-server%E5%9C%B0%E5%9D%80%E5%92%8C%E5%BE%AE%E6%9C%8D%E5%8A%A1%E5%90%8D%E7%A7%B0"><span class="toc-text">1.3、配置Nacos server地址和微服务名称</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-4%E3%80%81%E6%B7%BB%E5%8A%A0%E6%B3%A8%E8%A7%A3"><span class="toc-text">1.4、添加注解</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-5%E3%80%81%E8%AE%BF%E9%97%AENacos-Server%E5%90%8E%E5%8F%B0"><span class="toc-text">1.5、访问Nacos Server后台</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#2%E3%80%81Spring-Cloud%E6%95%B4%E5%90%88Nacos%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83"><span class="toc-text">2、Spring Cloud整合Nacos配置中心</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#2-1%E3%80%81%E4%BC%A0%E7%BB%9F%E9%85%8D%E7%BD%AE%E6%96%B9%E5%BC%8F"><span class="toc-text">2.1、传统配置方式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-2%E3%80%81%E5%BC%95%E5%85%A5Nacos-config%E4%BE%9D%E8%B5%96"><span class="toc-text">2.2、引入Nacos config依赖</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-3%E3%80%81%E9%85%8D%E7%BD%AENacos%E5%85%83%E6%95%B0%E6%8D%AE"><span class="toc-text">2.3、配置Nacos元数据</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-4%E3%80%81Nacos%E5%90%8E%E5%8F%B0%E6%96%B0%E5%A2%9E%E9%85%8D%E7%BD%AE"><span class="toc-text">2.4、Nacos后台新增配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-5%E3%80%81%E5%BC%80%E5%90%AF%E5%8A%A8%E6%80%81%E5%88%B7%E6%96%B0%E9%85%8D%E7%BD%AE"><span class="toc-text">2.5、开启动态刷新配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-6%E3%80%81%E6%9B%B4%E5%A4%9A"><span class="toc-text">2.6、更多</span></a></li></ol></li></ol></div></div></widget>




</div>


    </aside>
    <div class='l_main'>
      

      



<div class="bread-nav fs12"><div id="breadcrumb"><a class="cap breadcrumb" href="/">主页</a><span class="sep"></span><a class="cap breadcrumb" href="/">文章</a><span class="sep"></span><a class="cap breadcrumb-link" href="/categories/Spring-Cloud/">Spring Cloud</a></div><div id="post-meta">发布于&nbsp;<time datetime="2023-10-05T03:13:35.015Z">2023-10-05</time></div></div>

<article class='md-text content post'>
<h1 class="article-title"><span>Nacos使用笔记</span></h1>
<meta name="referrer" content="no-referrer"/>

<p>微服务部署下使用Nacos集成服务注册和发现，配置管理。</p>
<span id="more"></span>

<h1 id="1、Spring-Cloud整合Nacos注册中心"><a href="#1、Spring-Cloud整合Nacos注册中心" class="headerlink" title="1、Spring Cloud整合Nacos注册中心"></a>1、Spring Cloud整合Nacos注册中心</h1><h2 id="1-1、引入Nacos服务发现组件"><a href="#1-1、引入Nacos服务发现组件" class="headerlink" title="1.1、引入Nacos服务发现组件"></a>1.1、引入Nacos服务发现组件</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- nacos discovery 服务发现组件--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.alibaba.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-alibaba-nacos-discovery<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="1-2、下载Nacos-Server并启动"><a href="#1-2、下载Nacos-Server并启动" class="headerlink" title="1.2、下载Nacos Server并启动"></a>1.2、下载Nacos Server并启动</h2><ol>
<li>下载Nacos Server 压缩包</li>
</ol>
<p><a target="_blank" rel="noopener" href="https://github.com/alibaba/nacos/releases">https://github.com/alibaba/nacos/releases</a></p>
<ol start="2">
<li>启动 Server</li>
</ol>
<p>进入解压后文件夹或编译打包好的文件夹，找到如下相对文件夹 nacos&#x2F;bin，并对照操作系统实际情况之下如下命令，<code>-m standalone</code>表示单机模式启动。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Linux/Unix/Mac 操作系统，执行命令 </span></span><br><span class="line">sh startup.sh -m standalone</span><br><span class="line"><span class="comment"># Windows 操作系统，执行命令 </span></span><br><span class="line">startup.cmd -m standalone</span><br></pre></td></tr></table></figure>

<h2 id="1-3、配置Nacos-server地址和微服务名称"><a href="#1-3、配置Nacos-server地址和微服务名称" class="headerlink" title="1.3、配置Nacos server地址和微服务名称"></a>1.3、配置Nacos server地址和微服务名称</h2><ol>
<li>为每个微服务都配置Nacos Server 地址</li>
</ol>
<p>在每个微服务应用的 &#x2F;src&#x2F;main&#x2F;resources&#x2F;application.yml配置文件中配置 Nacos Server 地址。</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring</span>:<span class="string"></span></span><br><span class="line">   <span class="attr">cloud</span>:<span class="string"></span></span><br><span class="line">    <span class="attr">nacos</span>:<span class="string"></span></span><br><span class="line">      <span class="attr">discovery</span>:<span class="string"></span></span><br><span class="line">        <span class="attr">server-addr</span>: <span class="string">127.0.0.1:8848</span></span><br><span class="line"></span><br><span class="line">   <span class="attr">application</span>:<span class="string"></span></span><br><span class="line">     <span class="attr">name</span>: <span class="string">passjava-question</span></span><br></pre></td></tr></table></figure>

<h2 id="1-4、添加注解"><a href="#1-4、添加注解" class="headerlink" title="1.4、添加注解"></a>1.4、添加注解</h2><p>为每个服务使用 @EnableDiscoveryClient 注解开启服务注册与发现功能。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@EnableDiscoveryClient</span></span><br><span class="line"><span class="meta">@MapperScan(&quot;com.jun.passjava.question.dao&quot;)</span></span><br><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">PassjavaQuestionApplication</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        SpringApplication.run(PassjavaQuestionApplication.class, args);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="1-5、访问Nacos-Server后台"><a href="#1-5、访问Nacos-Server后台" class="headerlink" title="1.5、访问Nacos Server后台"></a>1.5、访问Nacos Server后台</h2><p>登录后台</p>
<p><a target="_blank" rel="noopener" href="http://localhost:8848/nacos/index.html#/login">http://localhost:8848/nacos/index.html#/login</a></p>
<p>用户名：nacos</p>
<p>密码：nacos</p>
<h1 id="2、Spring-Cloud整合Nacos配置中心"><a href="#2、Spring-Cloud整合Nacos配置中心" class="headerlink" title="2、Spring Cloud整合Nacos配置中心"></a>2、Spring Cloud整合Nacos配置中心</h1><h2 id="2-1、传统配置方式"><a href="#2-1、传统配置方式" class="headerlink" title="2.1、传统配置方式"></a>2.1、传统配置方式</h2><ol>
<li>application.properties文件中定义两个配置：</li>
</ol>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">member.nickname</span> = <span class="string">&quot;jun&quot;</span></span><br><span class="line"><span class="attr">member.age</span> = <span class="string">&quot;18&quot;</span></span><br></pre></td></tr></table></figure>



<ol>
<li>示例控制器中定义私有变量nickname和age，@value代表从配置中取值</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Value(&quot;$&#123;member.nickname&#125;&quot;)</span></span><br><span class="line"><span class="keyword">private</span>  String nickname;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Value(&quot;$member.age&quot;)</span></span><br><span class="line"><span class="keyword">private</span>  Integer age;</span><br></pre></td></tr></table></figure>



<ol>
<li>示例控制器中定义方法：获取nick和age的值</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RequestMapping(&quot;/test-local-config&quot;)</span></span><br><span class="line"><span class="keyword">public</span> R <span class="title function_">testLocalConfig</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> R.ok().put(<span class="string">&quot;nickname&quot;</span>, nickname).put(<span class="string">&quot;age&quot;</span>, age);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol>
<li>测试结果</li>
</ol>
<div class="tag-plugin image"><div class="image-bg"><img src="https://cdn.nlark.com/yuque/0/2023/png/36098302/1695641030655-435693bd-e552-4487-a943-ec1786855ca9.png" fancybox="true"/></div></div>

<ol>
<li>总结</li>
</ol>
<p>从配置文件中获取配置。这种方式的缺点是什么呢？如果要修改配置参数，则需要重新启动服务。如果服务很多，则需要重启所有服务，非常不方便。</p>
<p>有没有什么办法不停服务修改配置而且使其生效呢？</p>
<p>答案：有的，用Spring Cloud Alibaba的Nacos 组件就可以完成。</p>
<h2 id="2-2、引入Nacos-config依赖"><a href="#2-2、引入Nacos-config依赖" class="headerlink" title="2.2、引入Nacos config依赖"></a>2.2、引入Nacos config依赖</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.alibaba.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-alibaba-nacos-config<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>



<h2 id="2-3、配置Nacos元数据"><a href="#2-3、配置Nacos元数据" class="headerlink" title="2.3、配置Nacos元数据"></a>2.3、配置Nacos元数据</h2><ol>
<li>微服务下添加 &#x2F;src&#x2F;main&#x2F;resources&#x2F;bootstrap.properties 配置文件。</li>
</ol>
<p>注意：bootstrap.properties 是系统级的，优先级高于其他配置文件， application.properties 是应用级别的，加载比较晚，其次是bootstrap.yml、application.yml，所以引入 Nacos 组件时，需要配置 bootstrap.properties</p>
<ol start="2">
<li>配置 Nacos Config 元数据。</li>
</ol>
<p>需要配置Nacos的服务名，也就是对应Nacos管理平台的配置文件，和Nacos服务地址。</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring.application.name</span>=<span class="string">nacos-demo</span></span><br><span class="line"><span class="attr">spring.cloud.nacos.config.server-addr</span>=<span class="string">127.0.0.1:8848</span></span><br></pre></td></tr></table></figure>

<h2 id="2-4、Nacos后台新增配置"><a href="#2-4、Nacos后台新增配置" class="headerlink" title="2.4、Nacos后台新增配置"></a>2.4、Nacos后台新增配置</h2><p><strong>Data ID:</strong> nacos-demo.properties</p>
<p><strong>Group:</strong> DEFAULT_GROUP</p>
<p>配置格式：</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">user.name</span>=<span class="string">&quot;jun&quot;</span></span><br><span class="line"><span class="attr">user.age</span>=<span class="string">27</span></span><br></pre></td></tr></table></figure>


 <div class="tag-plugin image"><div class="image-bg"><img src="https://cdn.nlark.com/yuque/0/2023/png/36098302/1695783332627-d8a70864-b408-4640-9b3f-9cc3ffb5df37.png" fancybox="true"/></div></div>



<h2 id="2-5、开启动态刷新配置"><a href="#2-5、开启动态刷新配置" class="headerlink" title="2.5、开启动态刷新配置"></a>2.5、开启动态刷新配置</h2><p>添加注解@RefreshScope开启动态刷新配置功能。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RequestMapping(&quot;/test-local-config&quot;)</span></span><br><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@RefreshScope</span></span><br><span class="line"><span class="keyword">public</span> R <span class="title function_">testLocalConfig</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> R.ok().put(<span class="string">&quot;nickname&quot;</span>, name).put(<span class="string">&quot;age&quot;</span>,age);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>日志：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">2023</span>-09-<span class="number">27</span> <span class="number">10</span>:<span class="number">59</span>:<span class="number">06.646</span>  INFO <span class="number">13252</span> --- [-<span class="number">127.0</span><span class="number">.0</span><span class="number">.1_8848</span>] o.s.c.e.event.RefreshEventListener       : Refresh keys changed: [user.name]</span><br><span class="line"><span class="number">2023</span>-09-<span class="number">27</span> <span class="number">10</span>:<span class="number">59</span>:<span class="number">06.646</span>  INFO <span class="number">13252</span> --- [-<span class="number">127.0</span><span class="number">.0</span><span class="number">.1_8848</span>] c.a.nacos.client.config.impl.CacheData   : [fixed-<span class="number">127.0</span><span class="number">.0</span><span class="number">.1_8848</span>] [notify-ok] dataId=nacos-demo.properties, group=DEFAULT_GROUP, md5=bd3c381399ca063d5ee908060b8c1afa, listener=com.alibaba.cloud.nacos.refresh.NacosContextRefresher$<span class="number">1</span>@186a3635 </span><br><span class="line"><span class="number">2023</span>-09-<span class="number">27</span> <span class="number">10</span>:<span class="number">59</span>:<span class="number">06.647</span>  INFO <span class="number">13252</span> --- [-<span class="number">127.0</span><span class="number">.0</span><span class="number">.1_8848</span>] c.a.nacos.client.config.impl.CacheData   : [fixed-<span class="number">127.0</span><span class="number">.0</span><span class="number">.1_8848</span>] [notify-listener] time cost=2133ms in ClientWorker, dataId=nacos-demo.properties, group=DEFAULT_GROUP, md5=bd3c381399ca063d5ee908060b8c1afa, listener=com.alibaba.cloud.nacos.refresh.NacosContextRefresher$<span class="number">1</span>@186a3635 </span><br></pre></td></tr></table></figure>

<p> <code>user.name</code>更新了，通知了nacos-demo服务，刷新了配置。对应的配置id为nacos-demo.properties，分组为DEFAULT_GROUP。监听器为com.alibaba.cloud.nacos.refresh.NacosContextRefresher</p>
<p>测试结果：</p>
<div class="tag-plugin image"><div class="image-bg"><img src="https://cdn.nlark.com/yuque/0/2023/png/36098302/1695783517983-78bab6b2-f7e6-46cc-809d-c6bd9fd3e104.png" fancybox="true"/></div></div>

<h2 id="2-6、更多"><a href="#2-6、更多" class="headerlink" title="2.6、更多"></a>2.6、更多</h2><p><a target="_blank" rel="noopener" href="http://www.passjava.cn/#/01.PassJava/02.PassJava_Architecture/10.SpringCloud%E6%95%B4%E5%90%88Nacos%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83">命名空间、分组、多配置集用法。</a></p>





</article>

<div class="related-wrap reveal" id="read-next"><section class="body"><div class="item" id="prev"><div class="note">较新文章</div><a href="/2023/10/05/NodeJs&Vue%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE%E6%95%99%E7%A8%8B/">NodeJs&Vue安装配置教程</a></div><div class="item" id="next"><div class="note">较早文章</div><a href="/2023/10/05/MyBatis-Plus%E6%95%B4%E5%90%88%E7%AC%94%E8%AE%B0/">MyBatis-Plus整合笔记</a></div></section></div>






  <div class='related-wrap md-text reveal' id="comments">
    <section class='header cmt-title cap theme'>
      快来参与讨论吧
    </section>
    <section class='body cmt-body giscus'>
      

<svg class="loading" style="vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2709"><path d="M832 512c0-176-144-320-320-320V128c211.2 0 384 172.8 384 384h-64zM192 512c0 176 144 320 320 320v64C300.8 896 128 723.2 128 512h64z" p-id="2710"></path></svg>

<div id="giscus" data-repo="echoalways/giscus" data-repo-id="R_kgDOKjJRiQ" data-category="Announcements" data-category-id="DIC_kwDOKjJRic4CaUxu" data-mapping="pathname" data-strict="0" data-reactions-enabled="1" data-emit-metadata="0" data-input-position="top" data-theme="preferred_color_scheme" data-lang="zh-CN" data-loading="lazy" crossorigin="anonymous"></div>

    </section>
  </div>



      
<footer class="page-footer reveal fs12"><hr><div class="text" style="text-align:center;"><p>云无心以出岫@远岫♥</p>
<div><span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span>，<span id="busuanzi_container_site_pv">总访问量: <span id="busuanzi_value_site_pv"></span>次</span>，<span id="busuanzi_container_site_uv">访客数: <span id="busuanzi_value_site_uv"></span>人</span></div></div></footer>

<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<script>
  function createtime() {
    var now = new Date();
    var grt= new Date("10/03/2023 18:40:00");
    now.setTime(now.getTime()+250);
    days = (now - grt ) / 1000 / 60 / 60 / 24; dnum = Math.floor(days);
    hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum); hnum = Math.floor(hours);
    if(String(hnum).length ==1 ){hnum = "0" + hnum;} minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum);
    mnum = Math.floor(minutes); if(String(mnum).length ==1 ){mnum = "0" + mnum;}
    seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
    snum = Math.round(seconds); if(String(snum).length ==1 ){snum = "0" + snum;}
    document.getElementById("timeDate").innerHTML = "本站已运行 "+dnum+" 天 ";
    document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒";
  };
  setInterval("createtime()",250);
</script>

      <div class='float-panel mobile-only blur' style='display:none'>
  <button type='button' class='sidebar-toggle mobile' onclick='sidebar.toggle()'>
    <svg class="icon" style="width: 1em; height: 1em;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="15301"><path d="M566.407 808.3c26.9-0.1 49.3-20.8 51.6-47.6-1.9-27.7-23.9-49.7-51.6-51.6h-412.6c-28.2-1.4-52.6 19.5-55.5 47.6 2.3 26.8 24.6 47.5 51.6 47.6h416.5v4z m309.3-249.9c26.9-0.1 49.3-20.8 51.6-47.6-2.2-26.8-24.6-47.5-51.6-47.6h-721.9c-27.7-2.8-52.5 17.4-55.3 45.1-0.1 0.8-0.1 1.7-0.2 2.5 0.9 27.2 23.6 48.5 50.7 47.6H875.707z m-103.1-245.9c26.9-0.1 49.3-20.8 51.6-47.6-0.4-28.3-23.2-51.1-51.5-51.6h-618.9c-29.5-1.1-54.3 21.9-55.5 51.4v0.2c1.4 27.8 25.2 49.2 53 47.8 0.8 0 1.7-0.1 2.5-0.2h618.8z" p-id="15302"></path><path d="M566.407 808.3c26.9-0.1 49.3-20.8 51.6-47.6-1.9-27.7-23.9-49.7-51.6-51.6h-412.6c-28.2-1.4-52.6 19.5-55.5 47.6 1.9 27.7 23.9 49.7 51.6 51.6h416.5z m309.3-249.9c26.9-0.1 49.3-20.8 51.6-47.6-2.2-26.8-24.6-47.5-51.6-47.6h-721.9c-27.7-2.8-52.5 17.4-55.3 45.1-0.1 0.8-0.1 1.7-0.2 2.5 0.9 27.2 23.6 48.5 50.7 47.6H875.707z m-103.1-245.9c26.9-0.1 49.3-20.8 51.6-47.6-0.4-28.3-23.2-51.1-51.5-51.6h-618.9c-29.5-1.1-54.3 21.9-55.5 51.4v0.2c1.4 27.8 25.2 49.2 53 47.8 0.8 0 1.7-0.1 2.5-0.2h618.8z" p-id="15303"></path></svg>
  </button>
</div>

    </div>
  </div>
  <div class='scripts'>
    <script type="text/javascript">
  const stellar = {
    // 懒加载 css https://github.com/filamentgroup/loadCSS
    loadCSS: (href, before, media, attributes) => {
      var doc = window.document;
      var ss = doc.createElement("link");
      var ref;
      if (before) {
        ref = before;
      } else {
        var refs = (doc.body || doc.getElementsByTagName("head")[0]).childNodes;
        ref = refs[refs.length - 1];
      }
      var sheets = doc.styleSheets;
      if (attributes) {
        for (var attributeName in attributes) {
          if (attributes.hasOwnProperty(attributeName)) {
            ss.setAttribute(attributeName, attributes[attributeName]);
          }
        }
      }
      ss.rel = "stylesheet";
      ss.href = href;
      ss.media = "only x";
      function ready(cb) {
        if (doc.body) {
          return cb();
        }
        setTimeout(function () {
          ready(cb);
        });
      }
      ready(function () {
        ref.parentNode.insertBefore(ss, before ? ref : ref.nextSibling);
      });
      var onloadcssdefined = function (cb) {
        var resolvedHref = ss.href;
        var i = sheets.length;
        while (i--) {
          if (sheets[i].href === resolvedHref) {
            return cb();
          }
        }
        setTimeout(function () {
          onloadcssdefined(cb);
        });
      };
      function loadCB() {
        if (ss.addEventListener) {
          ss.removeEventListener("load", loadCB);
        }
        ss.media = media || "all";
      }
      if (ss.addEventListener) {
        ss.addEventListener("load", loadCB);
      }
      ss.onloadcssdefined = onloadcssdefined;
      onloadcssdefined(loadCB);
      return ss;
    },

    // 从 butterfly 和 volantis 获得灵感
    loadScript: (src, opt) => new Promise((resolve, reject) => {
      var script = document.createElement('script');
      if (src.startsWith('/')){
        src = stellar.config.root + src.substring(1);
      }
      script.src = src;
      if (opt) {
        for (let key of Object.keys(opt)) {
          script[key] = opt[key]
        }
      } else {
        // 默认异步，如果需要同步，第二个参数传入 {} 即可
        script.async = true
      }
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    }),

    // https://github.com/jerryc127/hexo-theme-butterfly
    jQuery: (fn) => {
      if (typeof jQuery === 'undefined') {
        stellar.loadScript(stellar.plugins.jQuery).then(fn)
      } else {
        fn()
      }
    }
  };
  stellar.version = '1.19.0';
  stellar.github = 'https://github.com/xaoxuu/hexo-theme-stellar/tree/1.19.0';
  stellar.config = {
    date_suffix: {
      just: '刚刚',
      min: '分钟前',
      hour: '小时前',
      day: '天前',
      month: '个月前',
    },
    root : '/',
  };

  // required plugins (only load if needs)
  stellar.plugins = {
    jQuery: 'https://gcore.jsdelivr.net/npm/jquery@3.6.2/dist/jquery.min.js'
  };

  if ('local_search') {
    stellar.search = {};
    stellar.search.service = 'local_search';
    if (stellar.search.service == 'local_search') {
      let service_obj = Object.assign({}, {"field":"all","path":"/search.json","content":true,"sort":"-date"});
      stellar.search[stellar.search.service] = service_obj;
    }
  }

  // stellar js
  stellar.plugins.stellar = Object.assign({"sites":"/js/plugins/sites.js","friends":"/js/plugins/friends.js","ghinfo":"/js/plugins/ghinfo.js","timeline":"/js/plugins/timeline.js","linkcard":"/js/plugins/linkcard.js","fcircle":"/js/plugins/fcircle.js","weibo":"/js/plugins/weibo.js"});

  stellar.plugins.marked = Object.assign("https://cdn.bootcdn.net/ajax/libs/marked/4.0.18/marked.min.js");
  // optional plugins
  if ('false' == 'true') {
    stellar.plugins.lazyload = Object.assign({"enable":false,"js":"https://gcore.jsdelivr.net/npm/vanilla-lazyload@17.8.3/dist/lazyload.min.js","transition":"blur"});
  }
  if ('true' == 'true') {
    stellar.plugins.swiper = Object.assign({"enable":true,"css":"https://unpkg.com/swiper@8.4.5/swiper-bundle.min.css","js":"https://unpkg.com/swiper@8.4.5/swiper-bundle.min.js"});
  }
  if ('' == 'true') {
    stellar.plugins.scrollreveal = Object.assign({"enable":null,"js":"https://gcore.jsdelivr.net/npm/scrollreveal@4.0.9/dist/scrollreveal.min.js","distance":"8px","duration":500,"interval":100,"scale":1});
  }
  if ('true' == 'true') {
    stellar.plugins.preload = Object.assign({"enable":true,"service":"flying_pages","instant_page":"https://gcore.jsdelivr.net/gh/volantis-x/cdn-volantis@4.1.2/js/instant_page.js","flying_pages":"https://gcore.jsdelivr.net/gh/gijo-varghese/flying-pages@2.1.2/flying-pages.min.js"});
  }
  if ('true' == 'true') {
    stellar.plugins.fancybox = Object.assign({"enable":true,"js":"https://gcore.jsdelivr.net/npm/@fancyapps/ui@4.0/dist/fancybox.umd.js","css":"https://gcore.jsdelivr.net/npm/@fancyapps/ui@4.0/dist/fancybox.css","selector":".swiper-slide img"});
  }
  if ('false' == 'true') {
    stellar.plugins.heti = Object.assign({"enable":false,"css":"https://unpkg.com/heti@0.9.2/umd/heti.min.css","js":"https://unpkg.com/heti@0.9.2/umd/heti-addon.min.js"});
  }
  if ('true' == 'true') {
    stellar.plugins.copycode = Object.assign({"enable":true,"js":"/js/plugins/copycode.js","default_text":"Copy","success_text":"Copied"});
  }
</script>

<!-- required -->

  
<script src="/js/main.js" async></script>



<!-- optional -->

  <script>
  function loadJS() {
    const els = document.querySelectorAll("#comments #giscus");
    if (els.length === 0) return;
    els.forEach((el, i) => {
      try {
        el.innerHTML = '';
      } catch (error) {
        console.log(error);
      }
      var script = document.createElement('script');
      script.src = 'https://giscus.app/client.js';
      script.async = true;
      for (let key of Object.keys(el.attributes)) {
        let attr = el.attributes[key];
        if (['class', 'id'].includes(attr.name) === false) {
          script.setAttribute(attr.name, attr.value);
        }
      }
      el.appendChild(script);
    });
  }
  window.addEventListener('DOMContentLoaded', (event) => {
    loadJS();
  });
</script>




<!-- inject -->


  </div>
</body>
</html>
